package com.test.test.dto.common;

import java.util.HashMap;
import java.util.Map;

/**
 * 统一返回结果说明(由于现在模块越来越多，由原来的统一编码改成按业务模块编码)
 */

public class RespConsts {


    public static final Integer OPERATE = 10000; // 学习评测系统服务操作()
	public static final Integer OPERATE_SUCCESS = OPERATE + 200;
    public static final Integer OPERATE_FAILED = OPERATE + 500;
    public static final Integer OPERATE_UNKNOWN = OPERATE + 501;
    public static final Integer OPERATE_REQ_ERROR = OPERATE + 502;
    public static final Integer OPERATE_SECURE_ERROR = OPERATE + 503;
    public static final Integer OPERATE_NOT_LOGIN_ERROR = OPERATE + 504;
    public static final Integer OPERATE_INTERNAL_ERROR = OPERATE + 505;
    public static final Integer OPERATE_PARAMETER_ERROR = OPERATE + 401;
    public static final Integer OPERATE_DATA_FORMAT_ERROR = OPERATE + 402;
    public static final Integer OPERATE_DATA_NOT_EXIST = OPERATE + 403;
    public static final Integer OPERATE_DATA_EXIST = OPERATE + 404;
    
    private static final Map<Integer, String> codeMessage = new HashMap<Integer, String>();

    static {
        /**
         * 学习评测系统服务
         */
        codeMessage.put(OPERATE_SUCCESS, "操作成功");
        codeMessage.put(OPERATE_FAILED, "操作失败");
        codeMessage.put(OPERATE_UNKNOWN, "未知错误。%s");
        codeMessage.put(OPERATE_REQ_ERROR, "请求错误");
        codeMessage.put(OPERATE_SECURE_ERROR, "认证未通过");
        codeMessage.put(OPERATE_NOT_LOGIN_ERROR, "用户未登录");
        codeMessage.put(OPERATE_INTERNAL_ERROR, "内部错误");
        codeMessage.put(OPERATE_PARAMETER_ERROR, "参数%s错误");
        codeMessage.put(OPERATE_DATA_FORMAT_ERROR, "数据格式错误");
        codeMessage.put(OPERATE_DATA_NOT_EXIST, "查询数据不存在");
        codeMessage.put(OPERATE_DATA_EXIST, "查询数据已存在");
    }

    /**
     * Get prompt message by code.
     *
     * @param code
     * @return
     */
    public static String getPrompt(Integer code) {
        if (codeMessage.containsKey(code)) {
            return codeMessage.get(code);
        } else {
            return "NO SUCH CODE ERROR: " + code;
        }
    }

    public static String getPromptWithFormat(Integer code, Object... values) {
        if (codeMessage.containsKey(code)) {
            return String.format(codeMessage.get(code), values);
        } else {
            return "NO SUCH CODE ERROR: " + code;
        }
    }

}
